package org.polyforms.repository.hibernate;

import javax.persistence.EntityManager;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.metadata.ClassMetadata;

/**
 * Utility for Hibernate.
 * 
 * @author Kuisong Tong
 * @since 1.0
 */
final class HibernateUtil {
    protected HibernateUtil() {
        throw new UnsupportedOperationException();
    }

    protected static Session getSession(final EntityManager entityManager) {
        return (Session) entityManager.getDelegate();
    }

    protected static SessionFactory getSessionFactory(final EntityManager entityManager) {
        return getSession(entityManager).getSessionFactory();
    }

    protected static ClassMetadata getClassMetadata(final EntityManager entityManager, final Class<?> clazz) {
        return getSessionFactory(entityManager).getClassMetadata(clazz);
    }
}
